<template>
    <scroll-view scroll-y 
    enable-flex
    class="top"
    @scrolltolower="handletop"
    >
      <view class="yop_list">
          <view class="top_item"
          v-for="item in list"
          :key="item.id"
          @click="handleItem(item)"
          >
              <image mode="widthFix" :src="item.img"></image>
          </view>
      </view>
    </scroll-view >
</template>

<script>
export default {
    data(){
        return {
            list:[],
            fag:true
        }
    },
    props:{
        urlObj:Object
    },
    mounted(){
        // console.log(this.urlObj)
        this.getlist()
    },
    watch:{
        urlObj(){
            // console.log("数据发生改变了")
            // console.log(this.urlObj)
            // 当页面发生改变时重新回去watch
        this.getlist()
        }
    },
    methods:{
        getlist(){
            this.request({
                url:this.urlObj.url,
                data:this.urlObj.params
            })
            .then(reslut=>{ 
                // console.log("123",reslut)
               if(reslut.res.videowp.length===0){
                   this.fag=false
                   uni.showToast({
                       title:"没有可以更新内容了",
                       icon:"none"
                   })
                   return;
               }
                this.list=[...this.list,...reslut.res.videowp]
            })
        },
        handletop(){
            if(this.fag){
            this.urlObj.params.skip+=this.urlObj.params.limit
            this.getlist()
            }else{
                uni.showToast({
                    title:"没有可加载内容了",
                    icon:"none"
                })
            }
         
        },
        handleItem(item){
            getApp().globalData.video=item
            uni.navigateTo({
                url:"/pages/videoitem/index"
            })
        }
    }
}
</script>

<style lang="scss" scoped>
  .top{
      height:calc( 100vh - 46px );
      .yop_list{
      display:flex;
      flex-wrap:wrap;
      .top_item{
          width:33.33%;
          border:2px solid #fff;
      }
      }
  }
</style>